#version 150

in vec4 iVertex;
in vec3 iColor;
in vec3 iNormal;
in vec2 iTexCoord;
in ivec4 iSkinIndices;
in vec4 iSkinWeights;

uniform mat4 uPMatrix;
uniform mat3 uNormalMatrix;

uniform mat4 uSkinMatrices[32];

uniform vec3 uLightPosition;

uniform int uBoneInspect;

const float cSpecularContribution=0.3;
const float cDiffuseContribution=1.0-cSpecularContribution;

out vec3 vVertexColor;
out vec2 vTexCoord;

void main()
{
    mat4 lMat=uSkinMatrices[iSkinIndices[0]]*iSkinWeights[0];
    
    for(int i=1;i<4;i++)
    {
        lMat+=uSkinMatrices[iSkinIndices[i]]*iSkinWeights[i];
    }

    vec3 lNorm=vec3(lMat*vec4(iNormal,0));
    lNorm=normalize(lNorm);
    float lIntensity=dot(lNorm,vec3(0,0,1));

    gl_Position=uPMatrix*lMat*iVertex;

    vVertexColor=lIntensity*iColor+0.3*iColor;
/*
    if(iSkinIndices[0]==uBoneInspect)
    {
        vVertexColor=vec3(0,iSkinWeights[0],0);
    }
    else if(iSkinIndices[1]==uBoneInspect)
    {
        vVertexColor=vec3(0,iSkinWeights[1],0);
    }
    else if(iSkinIndices[2]==uBoneInspect)
    {
        vVertexColor=vec3(0,iSkinWeights[2],0);
    }
    else if(iSkinIndices[3]==uBoneInspect)
    {
        vVertexColor=vec3(0,iSkinWeights[3],0);
    }
*/
    vTexCoord=iTexCoord;
}
